 <?php

    #Ensure that the client has provided a value for "FirstAddressToSearch"
        
        #Setup variables
       

        
        #Connect to Database
        $con = mysqli_connect("localhost","root","", "test");
        
        #Check connection
        if (mysqli_connect_errno()) {
            echo 'Database connection error: ' . mysqli_connect_error();
            exit();
        }
	$userdetails=0;
        
        #Query the database to get the user details.
	if (isset($_POST["FirstLatToSearch"]) && $_POST["FirstLatToSearch"] != "")
	{
 	$firstlat = $_POST["FirstLatToSearch"];
	$firslatrange1 = $firstlat - ($firstlat / 80.0);
	$firstlatrange2 = $firstlat + ($firstlat / 80.0);
	$firstlon = $_POST["FirstLonToSearch"];
	$firstlonrange1 = $firstlon - ($firstlon / 100.0);
	$firstlonrange2 = $firstlon + ($firstlon / 100.0);
        $userdetails = mysqli_query($con, "SELECT * FROM sup WHERE X_PA_ST_PLANE_S BETWEEN $firstlatrange1 and $firstlatrange2 AND Y_PA_ST_PLANE_S BETWEEN $firstlonrange1 and $firstlonrange2 LIMIT 50");
	}

        #If no data was returned, check for any SQL errors
        if (!$userdetails) {
            echo 'Could not run query: ' . mysqli_error($con);
            exit;
}
        
	
	while($e=mysqli_fetch_assoc($userdetails))
	{
		$output[]=$e;
	}

        #Output the JSON data
        echo json_encode($output); 
?> 